<?php
	class Modules_Requirements_View_ListRequirements
	{
		private $JS;
		public function __construct()
		{
			
		}
		public static function MakeAction($id)
		{
			$str="";
			$SetDefault='GetData({"module":"Projects.ChangeDefault","project":"'.$id.'"}, f=function(response)
			{
				var result=JSON.parse(response);
				if(result["result"]==1)
					location="index.php"
					alert("No permissions");
			});';
			$str.="<span class=\"buttonDefault\" onclick='".$SetDefault."'></span>";
			
			$SetDefault='GetData({"module":"Projects.RemoveProject","project":"'.$id.'"}, f=function(response)
			{
				var result=JSON.parse(response);
				if(result["result"]==1)
					location="index.php"
				else
					alert("No permissions");
			});';
			$str.="<span class=\"buttonRemove\" onclick='".$SetDefault."'></span>";
			return $str;
		}
		public function draw()
		{
			
			
			
			
			$str=file_get_contents(dirname(__FILE__)."/ListRequirements.html");
			
			$fields=array("Project","Client","Creator","Next Milestone","Actions");
			$header=new Modules_Common_Design_RowsHeader($fields);
			$table= new Modules_Common_Design_Table($header);
			$result=Modules_Common_DB_Projects::SearchByWorkspace($_SESSION['workspace']);
			foreach($result as $value)
			{
				$rows=new Modules_Common_Design_Rows($header);
				$row=array(
				"Project"=>$value->name,
				"Client"=>"cliente",
				"Creator"=>$value->creator,
				"Next Milestone"=>$value->getNext,
				"Actions"=>self::MakeAction($value->id)
				);
				$rows->setRow($row);
				$table->AddRows($rows);
			}
			
			
			$str=str_replace("<$=DATA=$>",$table->draw(),$str);	
			echo $str;
		
		}
		public function getJS()
		{
			return $this->JS;
		}
	}
	?>